const addrMgrStore = require('../../store/addressMgrStore.js').default;
const observer = require('../../libs/observer').observer;
const network = require('../../utils/network.js');
const jiaoyuMgr = require('../../store/jiayouStore.js');

Page(observer({

  /**
   * 页面的初始数据
   */
  props: {
    addrMgrStore: addrMgrStore
  },
  data: {
    orderInfo: null,
    cardInfo:null
  },

  onLoad:function(opt){
    const jiaoyuStore = jiaoyuMgr.store;
    this.setData({
      cardInfo: jiaoyuStore.cardInfo
    })
  },

  onShow: function() {
    addrMgrStore.refreshList();
    // this.createGasShopOrder();
  },

  exchangeIntegral: function() {
    const {
      id,
      shopId
    } = jiaoyuMgr.store.cardInfo;

    const activeAddr = this.props.addrMgrStore.activeAddr ;
    if(activeAddr==null){
      wx.showToast({
        title: '请选择收货地址',
      })
      return;
    }

    const parmas = {
      "shopId": shopId,
      "productId": id,
      "orderCategory": "shop_consume",
      "addressId": activeAddr.id  //配送地址

    }
    network.requestLoading('mp/client/shopOrder/exchangeIntegral', parmas, '请求中', (res) => {
      const payOrderNo = res.data.payOrderNo;
      wx.navigateTo({
        url: '/pages/pay-result/buycard-result?payOrderNo=' + payOrderNo,
      })
    })
  },

  goAddressList: function() {
    wx.navigateTo({
      url: '/pages/address/addressList',
    })
  },

// 提交订单
  confirmOrder: function() {
    var self = this ;
    wx.showModal({
      title: '提示',
      content: '确认购买吗？',
      success: function (res) {
        if (res.confirm) {
          self.exchangeIntegral();
        } else if (res.cancel) {
        }
      }
    })
  }
}))